package com.myzl.coal.mq;

import com.myzl.coal.dto.CmdCallBackDTO;
import com.myzl.coal.dto.CommandDTO;
import lombok.Data;
import lombok.extern.slf4j.Slf4j;
import org.springframework.amqp.rabbit.annotation.Exchange;
import org.springframework.amqp.rabbit.annotation.Queue;
import org.springframework.amqp.rabbit.annotation.QueueBinding;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.stereotype.Component;

import static com.myzl.coal.mq.MqConstant.*;


/**
 * @Author : JCccc
 * @CreateTime : 2019/9/3
 * @Description :
 **/
@Component
@Slf4j(topic = "admin-collect")
@Data
public class CommandConsumer {


    @RabbitListener(bindings = @QueueBinding(
            value = @Queue(name = MODBUS)
            ,exchange = @Exchange(name = COMMAND)
//            ,key = KEY
    ))
    public void json(CommandDTO commandDTO) {
        log.info("Exchange:{},queue:{} consumer message:{} ",COMMAND,MODBUS, commandDTO.toString());
        try {

        }catch (Exception e){
            log.error("发送命令命令执行结果异常:",e);
        }
    }

    @RabbitListener(bindings = @QueueBinding(
            value = @Queue(name = JSON)
            ,exchange = @Exchange(name = COMMAND)
//            ,key = KEY
    ))
    public void hex(CommandDTO commandDTO) {
        log.info("Exchange:{},queue:{} consumer message:{} ",COMMAND,MODBUS, commandDTO.toString());
        try {

        }catch (Exception e){
            log.error("发送命令命令执行结果异常:",e);
        }
    }
    @RabbitListener(bindings=@QueueBinding(
            value = @Queue(name =CMD_CALL_BACK),
            exchange = @Exchange(name = CMD_CALL_BACK)
    ))
    public void callBack(CmdCallBackDTO callBackDTO) {
        log.info("cmdCallBack queue consumer message:{} " , callBackDTO.toString());
        try{
        }catch (Exception e){
            log.error("命令执行结果异常:",e);
        }
    }

}
